package training_camp.day3.leetcode203;

class Solution {
     public ListNode removeElements(ListNode head, int val) {
         ListNode dummyHead = new ListNode();
         dummyHead.next = head;
         ListNode curr = head;
         ListNode prev = dummyHead;
         while(curr!=null){
             if (curr.val == val){
                 prev.next = curr.next;
             }
             else {
                 prev = curr;
             }
             curr = curr.next;
         }
         return dummyHead.next;
     }
}